package mao.mashibing.juc.atest;

import java.util.concurrent.locks.LockSupport;

/*
user：mao
data：2020/11/22
note：
*/
public class WithLockSupport {
    //为什么变量写到这里就可以在lambada表达式中。
    static Thread t1, t2 = null;
    public static void main(String[] args) {
        t1 = new Thread(() -> {
            for (int i = 0; i < 10; i++) {
                if (i == 5) {
                    LockSupport.unpark(t2);
                    LockSupport.park();
                }
                System.out.printf("生产到第%d个了\r\n", i);
            }
        });

        t2 = new Thread(() -> {
            LockSupport.park();
            System.out.println("监测到第五个了");
            LockSupport.unpark(t1);
        });

        t1.start();
        t2.start();
    }
}
